|
|
|
|
|
|
|
When you pass parameters to a procedure, youve had to pass those parameters in the exact order in which they were declared in the procedure. There are two problems with this: First, you may not always remember the order (although the syntax guide pop-up helps with this). Second, its not very readable later when youre just looking at the call to the procedure. To help solve these problems, you can pass in the parameters using the argument name itself. Heres an example: |
|
|
|
 |
|
|
|
|
Private Sub cmdNamed_Click()
Call ProcOptionalVar(intSecond:=10, _
intFirst:=50, _
vntName:="A Name")
End Sub |
|
|
|
|
|
|
|
|
Examples Filename: PassParms.frm and Func.bas |
|
|
|
|
|
|
|
|
Here, you see the call to the ProcOptionalVar procedure, where the actual argument names in the call are used. To do this, give the argument name followed by a colon and an equal sign (:=) and then the value you want to give to that argument. This helps make the code more readable, and it also allows you to pass in the arguments in any order you want. |
|
|
|
|
|
|
|
|
When you start to create your own functions and procedures, youll want to create a standard for how you name them. Heres a list of some general guidelines to follow: |
|
|
|
|
|
|
|
|
Your procedures and functions should always begin with a noun. |
|
|
|
|
|
|
|
|
Do not use an underscore in the name. This will help you distinguish between your procedures and Visual Basic event procedures. |
|
|
|
|
|
|
|
|
Use standard suffixes such as those shown in Table 9.1. |
|
|
|
|
| Table 9.1 Standard Suffixes for Naming Procedures. | | Suffix | Usage | Example | | Init | Initializes something only called once | FormInit | | Save | Saves data from a form to a table | FormSave |
|
|
|
|
|
|
(table continued on next page) |
|
|
|
|
|